package work729.work2;

public class UserBizImp implements  UserBiz {
  static boolean pd = false;
  User[] users = new User[]{
    new User("admin","123456","张三","admin@123.com"),
    new User("tom","123456","李四","timcat@cat.com")
  };
  @Override
  public void register(String username, String password, String rePassword, String name, String email) throws IllegalRegisterException {
    for (int i = 0; i <users.length ; i++) {
      if (users[i].getUsernamme().equals(username)){
        throw new IllegalRegisterException("该用户名已存在");
        //break;
      }
    }
    if (!password.equals(rePassword)){
      throw  new IllegalRegisterException("两次输入的password 不一致");
    }else {
      pd = true;
      System.out.println("注册成功");
    }
  }

  @Override
  public void login(String username, String password) throws IllegalLoginException {
    for (int i = 0; i <users.length ; i++) {
      if (users[i].getUsernamme().equals(username)){
        if (users[i].getPassword().equals(password)) {
          System.out.println("登录成功");
          pd = true;
          break;
          }else {
          throw new IllegalLoginException("username 和password 不匹配");
        }
        }
      }//循环结束
      if (!pd) {
        throw new IllegalLoginException("username 不存在");
      }

    }
}
